/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.javatrainning.duongnt.b1;

import java.util.Scanner;

/**
 *
 * @author ThuyDuong
 */
public class Bai3Muc1Phantichngto {

    public static void main(String[] args) {
        System.out.println("nhap a");
        long a;
        Scanner sc = new Scanner(System.in);
        a = sc.nextLong();
        System.out.println(a + "duoc phan tich thanh");
        pt(a);
    }

    public static boolean ngto(long a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void pt(long a) {
        long i = 2;
        int ok = 1;
        while (ok == 1) {
            //neu a la so nguyen to thi k phan tich nua,ok=0
            if (ngto(a)) {
                System.out.print(a);
                System.out.println();
                ok = 0;
            } else {
                if (ngto(i))// kiem tra i co phai so nguyen to k
                {
                    while (a % i == 0)// kiem tra a co chia het cho i thi in ra i
                    {
                        System.out.println(i + " ");
                        a = a / i;
                    }
                }
                i++;
            }
        }
    }
}
   
